package com.woniuxy.controller;

import com.woniuxy.entity.Question;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.TitleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 罗蔚
 * @Date 2022/4/26 17:18
 * @Description 题目的查询
 */
@Api(tags = "题目列表")
@RestController
@RequestMapping("/titleController")
public class TitleController {
    @Autowired
    TitleService titleService;

    /**
     * 向前端展示所有题目
     */
    @ApiOperation("列表")
    @GetMapping("/showAll/{currentPage}/{pageSize}")
    public ResponseEntity showAll(@PathVariable int currentPage, @PathVariable int pageSize) {
        return titleService.showAll(currentPage, pageSize);
    }

    /**
     * 模糊查询
     *
     * @param question
     * @return
     */
    @ApiOperation("查询")
    @PostMapping("/findLike/{currentPage}/{pageSize}")
    public ResponseEntity findLike(@RequestBody Question question, @PathVariable int currentPage, @PathVariable int pageSize) {
        return titleService.findLike(question, currentPage, pageSize);
    }

    /**
     * @param id
     * @return
     */
    @ApiOperation("删除一个")
    @DeleteMapping("/deleteOne/{id}")
    public ResponseEntity deleteOne(@PathVariable int id) {
        return titleService.deleteOne(id);
    }

    @ApiOperation("批量删除")
    @PostMapping("/delete")
    public ResponseEntity delete(@RequestBody Question question) {
        List<Integer> ids = question.getQuesstionIds();

        //创建一个数组接收传回来的多个id
        Integer[] arr = ids.toArray(new Integer[ids.size()]);

        return titleService.delete(arr);
    }

}
